package com.newworld.dmsapp2.activity;

import java.util.EnumMap;
import java.util.Map;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
import com.newworld.dmsapp2.R;
import com.newworld.dmsapp2.util.QRUtils;


public class TwoDcode1 extends Activity {
	private ImageView imgCode;
	private TextView imgCodeUrl,titlebar_left_center_title;
	private Bitmap logo;
	private LinearLayout titlebar_left_left_layout;

private ImageView qr_show;
//private SampleListLinearLayout lv_record;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_twodcode);
initViews();
initEvent();
}

protected void initViews() {

qr_show = (ImageView) findViewById(R.id.imgCode);
imgCodeUrl = (TextView)findViewById(R.id.imgCodeUrl);
titlebar_left_center_title = (TextView)findViewById(R.id.titlebar_left_center_title);
titlebar_left_center_title.setText("二维码分享");
titlebar_left_left_layout= (LinearLayout)findViewById(R.id.titlebar_left_left_layout);

DisplayMetrics outMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
int w = outMetrics.widthPixels * 8 / 11;//设置宽度
ViewGroup.LayoutParams layoutParams = qr_show.getLayoutParams();
layoutParams.height = layoutParams.width = w;//设置高度
qr_show.setLayoutParams(layoutParams);

try {
//Bitmap bitmap = QRUtils.encodeToQRWidth("http://write.blog.csdn.net/", w);//要生成二维码的内容，我这就是一个网址
	Bitmap bitmap = QRUtils.encodeToQRWidth("http://www.pgyer.com/NewWorldApp/", w);
	qr_show.setImageBitmap(bitmap);
	Log.e("生成二维码","二维码生成成功");
}
catch (Exception e) {
e.printStackTrace();
Toast.makeText(this, "生成二维码失败", Toast.LENGTH_SHORT);
}
}

private void initEvent() {
	// TODO 自动生成的方法存根
	titlebar_left_left_layout.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			onBackPressed();
		}
	});
	
}
}
